// eslint-disable-next-line @typescript-eslint/no-var-requires
const os = require('os');

const vmwarePattern = /VMware/i;
const vitrualBoxPattern = /VirtualBox/;

function getLocalIpAddrs(excludeLocalhost = false) {
  const ips = [];
  const networks = os.networkInterfaces();
  const names = Object.keys(networks);

  for (const name of names) {
    if (vmwarePattern.test(name) || vitrualBoxPattern.test(name)) {
      continue;
    }
    const values = networks[name];
    for (const networkItem of values) {
      if (networkItem.family === 'IPv4') {
        if (excludeLocalhost && networkItem.address === '127.0.0.1') {
          continue;
        }
        ips.push(networkItem.address);
      }
    }
  }
  return ips;
}

console.log(getLocalIpAddrs(true));
